package com.wolf.etl.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.wolf.exception.WolfException;
import com.wolf.provider.order.info.FieldInfo;
import com.wolf.provider.order.info.IdInfo;
import com.wolf.provider.order.info.TableInfo;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * Created by tommy's father on 2017/8/22.
 */
@TableInfo(value = "etl_table_filter")
public class EtlTableFilterModel {

    @IdInfo
    private Long id;

    /**
     * 创建人
     */
    @FieldInfo(value = "creator")
    private String creator = "admin";

    /**
     * 创建时间
     */
    @FieldInfo(value = "create_time")
    private Date create_time = new Date();

    /**
     * 修改人
     */
    @JSONField(format="yyyy-MM-dd")//数据库导出页面时json格式化
    @FieldInfo(value = "modified_person")
    private String modified_person;

    /**
     * 修改时间
     */
    @JSONField(format="yyyy-MM-dd")//数据库导出页面时json格式化
    @FieldInfo(value = "modified_time")
    private Date modified_time;

    /**
     * 租户id
     */
    @FieldInfo(value = "client_id")
    private Long client_id = 100L;

    @FieldInfo(value = "filter_id")
    private Long filter_id;

    @FieldInfo(value = "etl_table_id")
    private Long etl_table_id;

    @FieldInfo(value = "master_table_id")
    private Long master_table_id;

    @FieldInfo(value = "formula")
    private String formula;

    @FieldInfo(value = "column_name")
    private String column_name;

    @FieldInfo(value = "column_value1")
    private String column_value1;

    @FieldInfo(value = "column_value2")
    private String column_value2;

    @FieldInfo(value = "info_type")
    private String info_type;

    @FieldInfo(value = "status")
    private int status;

    @FieldInfo(value = "value_format")
    private String value_format;

    public String getValue_format() {
        return value_format;
    }

    public void setValue_format(String value_format) {
        this.value_format = value_format;
    }

    public Long getFilter_id() {
        return filter_id;
    }

    public void setFilter_id(Long filter_id) {
        this.filter_id = filter_id;
    }

    public Long getEtl_table_id() {
        return etl_table_id;
    }

    public void setEtl_table_id(Long etl_table_id) {
        this.etl_table_id = etl_table_id;
    }

    public Long getMaster_table_id() {
        return master_table_id;
    }

    public void setMaster_table_id(Long master_table_id) {
        this.master_table_id = master_table_id;
    }

    public String getFormula() {
        return formula;
    }

    public void setFormula(String formula) {
        this.formula = formula;
    }

    public String getColumn_name() {
        return column_name;
    }

    public void setColumn_name(String column_name) {
        this.column_name = column_name;
    }

    public String getColumn_value1() {
        return column_value1;
    }

    public void setColumn_value1(String column_value1) {
        this.column_value1 = column_value1;
    }

    public String getColumn_value2() {
        return column_value2;
    }

    public void setColumn_value2(String column_value2) {
        this.column_value2 = column_value2;
    }

    public String getInfo_type() {
        return info_type;
    }

    public void setInfo_type(String info_type) {
        this.info_type = info_type;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getCreator() {
        return creator;
    }

    public void setCreator(String creator) {
        this.creator = creator;
    }

    public Date getCreate_time() {
        return create_time;
    }

    public void setCreate_time(Date create_time) {
        this.create_time = create_time;
    }

    public String getModified_person() {
        return modified_person;
    }

    public void setModified_person(String modified_person) {
        this.modified_person = modified_person;
    }

    public Date getModified_time() {
        return modified_time;
    }

    public void setModified_time(Date modified_time) {
        this.modified_time = modified_time;
    }

    public Long getClient_id() {
        return client_id;
    }

    public void setClient_id(Long client_id) {
        this.client_id = client_id;
    }

    public void check() {
        if (etl_table_id < 1L) {
            throw new WolfException(String.format("The ETL filter record that it's id[%s].", etl_table_id));
        }

        if (StringUtils.isEmpty(column_name)) {
            throw new WolfException(String.format("The ETL filter record that it's id[%s] and column name is empty.", this.filter_id));
        }

//        if(!SQL_FORMULA.onRange(this.formula)){
//            throw new WolfException(String.format("The ETL filter record that it's id[%s] and formula[value=>%s] is not appropriate type.",
//                    filter_id,
//                    formula));
//        }
//
//        if (SQL_FORMULA.BETWEEN_AND.equals(this.formula)) {
//            if (!DateUtil.isDateFormat(column_value1)) {
//                throw new WolfException(String.format("The ETL filter record that it's id[%s] and column value1 is not datetime format."));
//            }
//
//            if (!DateUtil.isDateFormat(column_value2)) {
//                throw new WolfException(String.format("The ETL filter record that it's id[%s] and column value2 is not datetime format."));
//            }
//        }
    }
}
